package name.sra.util;


public class RgbUtils {
	
	public static double calculateIntensity(int rgb) {
		String rgbHexa = Integer.toHexString(rgb);
		return calculateIntensity(rgbHexa);
	}
	/** Calculate over 100 */
	public static double calculateIntensity(String rgb) {
		int length = rgb.length();
		double red = ((double) Integer.parseInt(rgb.substring(length -2), 16))/((double) Integer.parseInt("FF", 16));
		double blue = ((double) Integer.parseInt(rgb.substring(length - 4,
												length -2), 16))/((double) Integer.parseInt("FF", 16));
		double green = ((double) Integer.parseInt(rgb.substring(length - 6,
												length -4), 16))/((double) Integer.parseInt("FF", 16));
		double[] rgbD = new double[]{rev(red), rev(blue), rev(green)};
		return dist(rgbD);
	}
	
	private static double rev(double value) {
		return 1.0 - value;
	}
	
	private static double dist(double[] coords) {
		double res = 0;
		for (int i = 0;i < coords.length;i++) {
			res += coords[i] * coords[i];
		}
		return Math.sqrt(res)/Math.sqrt(coords.length);
	}
	
//	private static createLine()
}
